<!DOCTYPE HTML>
<html>

<head>
	<link rel="bookmark"  type="image/x-icon"  href="/img/logo_miccall.png"/>
	<link rel="shortcut icon" href="/img/logo_miccall.png">
	
			    <title>
    Ame雨
    </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <link rel="stylesheet" href="/amelin-ting/css/mic_main.css" />
    <link rel="stylesheet" href="/amelin-ting/css/dropdownMenu.css" />
    <meta name="keywords" content="Ame雨" />
    
    	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
	 
    <noscript>
        <link rel="stylesheet" href="/amelin-ting/css/noscript.css" />
    </noscript>
    <style type="text/css">
        body:before {
          content: ' ';
          position: fixed;
          top: 0;
          background: url('/amelin-ting/img/bg.jpg') center 0 no-repeat;
          right: 0;
          bottom: 0;
          left: 0;
          background-size: cover; 
        }
    </style>

			    
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script async type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


    <script src="/amelin-ting/js/jquery.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrollex.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrolly.min.js"></script>
    <script src="/amelin-ting/js/skel.min.js"></script>
    <script src="/amelin-ting/js/util.js"></script>
    <script src="/amelin-ting/js/main.js"></script>
	
<meta name="generator" content="Hexo 5.4.0"></head>
    
		
<!-- Layouts -->



<!--  代码渲染  -->
<link rel="stylesheet" href="/css/prism_coy.css" />
<link rel="stylesheet" href="/css/typo.css" />
<!-- 文章页 -->
<body class="is-loading">
    <!-- Wrapper 外包 s-->
    <div id="wrapper" class="fade-in">
        <!-- Intro 头部显示 s -->
        <!-- Intro 头部显示 e -->
        <!-- Header 头部logo start -->
        <header id="header">
    <a href="/amelin-ting/" class="logo">Art Space</a>
</header>
        <!-- Nav 导航条 start -->
        <nav id="nav" class="special" >
            <ul class="menu links" >
			<!-- Homepage  主页  --> 
			<li >
	            <a href="/amelin-ting/" rel="nofollow">主页</a>
	        </li>
			<!-- categories_name  分类   --> 
	        
	        <li class="active">
	            <a href="#s1">分类</a>
	                    <ul class="submenu">
	                        <li>
	                        <a class="category-link" href="/amelin-ting/categories/Go/">Go</a></li><li><a class="category-link" href="/amelin-ting/categories/django/">django</a></li><li><a class="category-link" href="/amelin-ting/categories/drf/">drf</a></li><li><a class="category-link" href="/amelin-ting/categories/gin/">gin</a></li><li><a class="category-link" href="/amelin-ting/categories/go/">go</a></li><li><a class="category-link" href="/amelin-ting/categories/linux/">linux</a></li><li><a class="category-link" href="/amelin-ting/categories/mysql/">mysql</a></li><li><a class="category-link" href="/amelin-ting/categories/python/">python</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">内网穿透</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%89%8D%E7%AB%AF/">前端</a>
	                    </ul>
	        </li>
	        
	        <!-- archives  归档   --> 
	        
	        
		        <!-- Pages 自定义   -->
		        
		        <li>
		            <a href="/about/" title="简历">
		                简历
		            </a>
		        </li>
		        
		        <li>
		            <a href="/group/" title="团队">
		                团队
		            </a>
		        </li>
		        
		        <li>
		            <a href="/gallery/" title="图库">
		                图库
		            </a>
		        </li>
		        
		        <li>
		            <a href="/tag/" title="标签">
		                标签
		            </a>
		        </li>
		        


            </ul>
            <!-- icons 图标   -->
			<ul class="icons">
                    
                    <li>
                        <a title="github" href="https://github.com/miccall" target="_blank" rel="noopener">
                            <i class="icon fa fa-github"></i>
                        </a>
                    </li>
                    
                    <li>
                        <a title="500px" href="http://500px.com" target="_blank" rel="noopener">
                            <i class="icon fa fa-500px"></i>
                        </a>
                    </li>
                    
			</ul>
</nav>

        <div id="main" >
            <div class ="post_page_title_img" style="height: 25rem;background-image: url(https://img1.baidu.com/it/u=3544056127,2026924496&amp;fm=26&amp;fmt=auto);background-position: center; background-repeat:no-repeat; background-size:cover;-moz-background-size:cover;overflow:hidden;" >
                <a href="#" style="padding: 4rem 4rem 2rem 4rem ;"><h2 >python面向对象</h2></a>
            </div>
            <!-- Post -->
            <div class="typo" style="padding: 3rem;">
                <h2 id="一、类与对象介绍"><a href="#一、类与对象介绍" class="headerlink" title="一、类与对象介绍"></a>一、类与对象介绍</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>面向对象</span><br><span class="line">    面向对象就是一种编程思想</span><br><span class="line">    面向过程也是一种编程思想  </span><br><span class="line">    <span class="comment"># 核心就是过程</span></span><br><span class="line">    <span class="comment"># 过程就是&#x27;流水线&#x27;,用来分步骤解决问题的</span></span><br><span class="line">    <span class="comment"># 过程的核心思想就是将程序流程化进而简单化</span></span><br><span class="line">    面向对象  <span class="comment"># 核心是对象二字</span></span><br><span class="line">    对象:对象就是容器，容器是用来盛放东西的(盛放什么东西)</span><br><span class="line">        用来盛放数据与功能的。</span><br><span class="line">        ---所以说对象就是<span class="string">&#x27;数据&#x27;</span>跟<span class="string">&#x27;功能&#x27;</span>的集合体</span><br><span class="line">        ---对象就是将程序<span class="string">&#x27;整合&#x27;</span></span><br><span class="line">        程序=数据+功能</span><br><span class="line">        学习对象就是将数据与功能整合到一起的方法</span><br><span class="line">        函数是放功能的容器</span><br><span class="line">        面向对象是一种更好的实现数据和功能整合到一起的方法</span><br><span class="line">    类:就是将对象做一个个区分，为了解决对象重复存取的问题</span><br><span class="line">        所以说类也是一种容器，该容器用来存放同类对象共有的数据与功能。</span><br><span class="line">        也可以将类叫做对象。</span><br><span class="line">        我们在访问数据的时候是先从对象里面的空间里面找，然后在从类的空间里面找</span><br><span class="line"></span><br><span class="line">----------------类的语法:----------------</span><br><span class="line"><span class="number">1.</span>先定义类</span><br><span class="line">    <span class="class"><span class="keyword">class</span> 定义类， 类中可以有任何的代码</span></span><br><span class="line"><span class="class">    1.变量的定义，2.功能的定义</span></span><br><span class="line"><span class="class">    类体代码在定义时候就运行了，就会产生名称空间。</span></span><br><span class="line"><span class="class">    这个时候对比一下(<span class="params">函数会在调用的时候才产生名称空间，而类在定义阶段就产生名称空间</span>)</span></span><br><span class="line"><span class="class">    <span class="title">print</span>(<span class="params">Student.__dict__</span>)  # 可以查看类的名称空间里面的名字</span></span><br><span class="line"><span class="class">    类中存放的是对象共有的东西，本质是给对象用的，类自己也可以用</span></span><br><span class="line"><span class="class">    <span class="title">print</span>(<span class="params">Student.__dict__[<span class="string">&#x27;sss&#x27;</span>]</span>)  # 可以取出类里面的值</span></span><br><span class="line"><span class="class">    <span class="title">python</span>给我们提供了一种专门的取值方法</span></span><br><span class="line"><span class="class">    属性访问语法，这个<span class="title">sss</span>不能称为是字符串，而是<span class="title">Student</span>这个类的一个属性</span></span><br><span class="line"><span class="class">    类的属性无非就两种(<span class="params"><span class="number">1.</span>访问数据属性，<span class="number">2.</span>访问函数属性</span>)</span></span><br><span class="line"><span class="class">    <span class="title">print</span>(<span class="params">Student.sss</span>)  # 本质就跟上面的取值一样，但是简便了很多</span></span><br><span class="line"><span class="class">    类跟对象是有关联的</span></span><br><span class="line"><span class="class">2.在调用类产生对象</span></span><br><span class="line"><span class="class">    类跟对象是有关联的,如果想让对象跟类有关联，必须用刚刚造出来的类调用一     下。 需要强调的是这个调用不会执行代码，因为类在定义的时候就执行代码过     了。只要调用<span class="title">Student</span>()就会帮你产生一个对象，就会建立类和这个对象的关联     此时这个对象还是空的对象。需要你往里面添加。然后可以得到他的返回值，这个返回值就是对象。对象放的也是数据跟功能</span></span><br><span class="line"><span class="class">    所以对象在刚刚造出来的时候，应该为他初始化定制他独有的属性(<span class="params">数据初始化</span>)</span></span><br><span class="line"><span class="class">    最好是不用自己产生，在调用的时候会自动把对象初始化</span></span><br><span class="line"><span class="class">    所以把下面的函数也放进类里面。只要调用类，就会把空对象传给<span class="title">__init__</span>这个函数，调用的时候后三个参数需要自己来传</span></span><br><span class="line"><span class="class">    <span class="title">def</span> <span class="title">__init__</span>(<span class="params">obj,参数<span class="number">1</span>,参数<span class="number">2</span>,参数<span class="number">3.</span>....</span>):</span>  </span><br><span class="line">        obj.stu_name = 参数<span class="number">1</span></span><br><span class="line">        obj.stu_age = 参数<span class="number">2</span></span><br><span class="line">        obj.stu_gender = 参数<span class="number">3</span></span><br><span class="line">    在类定义阶段不会触发，在调用阶段自动触发</span><br><span class="line">    Stu1_obj = Student(参数<span class="number">1</span>,参数<span class="number">2</span>,参数<span class="number">3</span>)</span><br><span class="line">    调用类的过程又称为实例化(你属于人类，但是不能说人类是你，你只是人类实际存在的一个案例，这就叫实例)</span><br><span class="line">    调用类是为了产生对象的，这个过程有人称之为实例化，将类这个抽象的东西，实例化</span><br><span class="line">    -----------------调用类发生了三件事------------</span><br><span class="line">    <span class="number">1.</span>先产生一个空对象</span><br><span class="line">    <span class="number">2.</span>会调用类中的__init__方法，然后将空对象以及调用类时括号内传入的参数一同传给__init__方法</span><br><span class="line">    <span class="number">3.</span>返回初始化完的对象，然后可以做一个赋值操作可以看到对象里面的结果</span><br><span class="line">    ------------总结__init__方法------------</span><br><span class="line">    <span class="number">1.</span>会在调用类时自动触发执行，用来为对象初始化自己独有的数据</span><br><span class="line">    <span class="number">2.</span>__init__内应该存放的是为对象初始化属性的功能，当然你也可以存放任意你想写的代码，想要在类调用时就立即执行的代码都可以放到该方法内</span><br><span class="line">    <span class="number">3.</span>调用类的返回值并不是__init__,  __init__方法必须返回<span class="literal">None</span>,不能返回非<span class="literal">None</span>的值</span><br><span class="line">    -------------------一个完整的类的形式----------</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Student</span>:</span></span><br><span class="line">        <span class="comment"># 1.变量的定义</span></span><br><span class="line">        stu_school=<span class="string">&#x27;oldboy&#x27;</span></span><br><span class="line">        <span class="comment"># 空对象</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">obj,x,y,z</span>):</span></span><br><span class="line">            obj.stu_name=x</span><br><span class="line">            obj.stu_age=y</span><br><span class="line">            obj.stu_gender=z</span><br><span class="line">         </span><br><span class="line">        <span class="comment"># 功能的定义</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">tell_stu_info</span>(<span class="params">stu_obj</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;学生信息:名字%s 年龄%s 性别%s&#x27;</span> % (</span><br><span class="line">            stu_obj[<span class="string">&#x27;stu_name&#x27;</span>],</span><br><span class="line">            stu_obj[<span class="string">&#x27;stu_age&#x27;</span>],</span><br><span class="line">            stu_obj[<span class="string">&#x27;stu_gender&#x27;</span>]))</span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">set_info</span>(<span class="params">stu_obj,x,y,z</span>):</span></span><br><span class="line">            stu_obj[<span class="string">&#x27;stu_name&#x27;</span>]=x</span><br><span class="line">            stu_obj[<span class="string">&#x27;stu_age&#x27;</span>]=y</span><br><span class="line">            stu_obj[<span class="string">&#x27;stu_gender&#x27;</span>]=z</span><br><span class="line">stu1_obj = Student(<span class="string">&#x27;egon&#x27;</span>,<span class="number">18</span>,<span class="string">&#x27;male&#x27;</span>)</span><br><span class="line"><span class="number">3.</span>属性查找的顺序</span><br><span class="line">类中存放是与对象共有的数据与功能</span><br><span class="line"><span class="number">1.</span>类可以访问：访问的是类的数据属性或者是类的函数属性</span><br><span class="line"><span class="number">2.</span>其实类中的东西是给对象用的:类的数据属性是共享给所有对象用的，大家访问的地址都一样</span><br><span class="line">类的函数属性是绑定给对象用的，不同的对象</span><br><span class="line">绑定方法的特殊之处，谁来调用谁当做第一个参数传入该函数内</span><br><span class="line">                                          </span><br></pre></td></tr></table></figure>

<h2 id="隐藏属性"><a href="#隐藏属性" class="headerlink" title="隐藏属性"></a>隐藏属性</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line">一：封装介绍</span><br><span class="line">    封装是面向对象三大特性最核心的一个特性</span><br><span class="line">    封装&lt;-&gt;整合</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">二、将封装的属性进行隐藏操作</span><br><span class="line"><span class="number">1</span>、如何隐藏：在属性名前加__前缀,就会实现一个对外隐藏属性效果</span><br><span class="line">	该隐藏需要注意的问题：</span><br><span class="line">        I:在类外部无法直接访问双下滑线开头的属性，但知道了类名和属性名就可以拼出名字：_类名__属性，然后就可以访问了，如			Foo._A__N，所以说这种操作并没有严格意义上地限制外部访问，仅仅只是一种语法意义上的变形。</span><br><span class="line">            <span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">                __x = <span class="number">1</span>  <span class="comment"># _Foo__x</span></span><br><span class="line"></span><br><span class="line">                <span class="function"><span class="keyword">def</span> <span class="title">__f1</span>(<span class="params">self</span>):</span>  <span class="comment"># _Foo__f1</span></span><br><span class="line">                    <span class="built_in">print</span>(<span class="string">&#x27;from test&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            <span class="built_in">print</span>(Foo.__dict__)</span><br><span class="line">            <span class="built_in">print</span>(Foo._Foo__x)</span><br><span class="line">            <span class="built_in">print</span>(Foo._Foo__f1)</span><br><span class="line"></span><br><span class="line">		II：这种隐藏对外不对内,因为__开头的属性会在检查类体代码语法时统一发生变形</span><br><span class="line">            <span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">                __x = <span class="number">1</span>  <span class="comment"># _Foo__x = 1</span></span><br><span class="line"></span><br><span class="line">                <span class="function"><span class="keyword">def</span> <span class="title">__f1</span>(<span class="params">self</span>):</span>  <span class="comment"># _Foo__f1</span></span><br><span class="line">                    <span class="built_in">print</span>(<span class="string">&#x27;from test&#x27;</span>)</span><br><span class="line"></span><br><span class="line">                <span class="function"><span class="keyword">def</span> <span class="title">f2</span>(<span class="params">self</span>):</span>		</span><br><span class="line">                    <span class="built_in">print</span>(self.__x) <span class="comment"># print(self._Foo__x)</span></span><br><span class="line">                    <span class="built_in">print</span>(self.__f1) <span class="comment"># print(self._Foo__f1)</span></span><br><span class="line"></span><br><span class="line">            <span class="built_in">print</span>(Foo.__x)</span><br><span class="line">            <span class="built_in">print</span>(Foo.__f1)</span><br><span class="line">            obj=Foo()</span><br><span class="line">            obj.f2()</span><br><span class="line"></span><br><span class="line">		III: 这种变形操作只在检查类体语法的时候发生一次，</span><br><span class="line">            <span class="comment"># 之后定义的__开头的属性都不会变形</span></span><br><span class="line">            <span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">                __x = <span class="number">1</span>  <span class="comment"># _Foo__x = 1</span></span><br><span class="line"></span><br><span class="line">                <span class="function"><span class="keyword">def</span> <span class="title">__f1</span>(<span class="params">self</span>):</span>  <span class="comment"># _Foo__f1</span></span><br><span class="line">                    <span class="built_in">print</span>(<span class="string">&#x27;from test&#x27;</span>)</span><br><span class="line"></span><br><span class="line">                <span class="function"><span class="keyword">def</span> <span class="title">f2</span>(<span class="params">self</span>):</span></span><br><span class="line">                    <span class="built_in">print</span>(self.__x) <span class="comment"># print(self._Foo__x)</span></span><br><span class="line">                    <span class="built_in">print</span>(self.__f1) <span class="comment"># print(self._Foo__f1)</span></span><br><span class="line"></span><br><span class="line">            Foo.__y=<span class="number">3</span></span><br><span class="line">            <span class="built_in">print</span>(Foo.__dict__)</span><br><span class="line">            <span class="built_in">print</span>(Foo.__y)</span><br><span class="line"></span><br><span class="line">            <span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">                __x = <span class="number">1</span>  <span class="comment"># _Foo__x = 1</span></span><br><span class="line"></span><br><span class="line">                <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self,name,age</span>):</span></span><br><span class="line">                    self.__name=name</span><br><span class="line">                    self.__age=age</span><br><span class="line"></span><br><span class="line">            obj=Foo(<span class="string">&#x27;egon&#x27;</span>,<span class="number">18</span>)</span><br><span class="line">            <span class="built_in">print</span>(obj.__dict__)</span><br><span class="line">            <span class="built_in">print</span>(obj.name,obj.age)</span><br><span class="line">		</span><br><span class="line"><span class="number">2</span>、为何要隐藏？</span><br><span class="line">    I、隐藏数据属性将数据隐藏起来就限制了类外部对数据的直接操作，然后类内应该提供相应的接口来允许类外部间接地操作数据，接口之	上可以附加额外的逻辑来对数据的操作进行严格地控制：</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">People</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name</span>):</span></span><br><span class="line">            self.__name = name</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">get_name</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="comment"># 通过该接口就可以间接地访问到名字属性</span></span><br><span class="line">            <span class="comment"># print(&#x27;小垃圾，不让看&#x27;)</span></span><br><span class="line">            <span class="built_in">print</span>(self.__name)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">set_name</span>(<span class="params">self,val</span>):</span></span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">type</span>(val) <span class="keyword">is</span> <span class="keyword">not</span> <span class="built_in">str</span>:</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&#x27;小垃圾，必须传字符串类型&#x27;</span>)</span><br><span class="line">                <span class="keyword">return</span></span><br><span class="line">            self.__name=val</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj = People(<span class="string">&#x27;egon&#x27;</span>)</span><br><span class="line">    <span class="comment"># print(obj.name) # 无法直接用名字属性</span></span><br><span class="line">    <span class="comment"># obj.set_name(&#x27;EGON&#x27;)</span></span><br><span class="line">    obj.set_name(<span class="number">123123123</span>)</span><br><span class="line">    obj.get_name()</span><br><span class="line">II、隐藏函数/方法属性：目的的是为了隔离复杂度</span><br></pre></td></tr></table></figure>



<h2 id="property"><a href="#property" class="headerlink" title="property"></a>property</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># property 其实就是装饰器</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">People</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, height, weight</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.height = height</span><br><span class="line">            self.weight = weight</span><br><span class="line"></span><br><span class="line"><span class="meta">        @property</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">blm</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="keyword">return</span> self.weight / (self.height ** <span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj1 = People(<span class="string">&#x27;ame&#x27;</span>, <span class="number">1.75</span>, <span class="number">85</span>)</span><br><span class="line">    <span class="built_in">print</span>(obj1.blm)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 在隐藏属性的时候 property的用法</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">People</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name</span>):</span></span><br><span class="line">            self.__name = name</span><br><span class="line"></span><br><span class="line"><span class="meta">        @property</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">name</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(self.__name)</span><br><span class="line"></span><br><span class="line"><span class="meta">        @name.setter</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">name</span>(<span class="params">self, val</span>):</span></span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">type</span>(val) <span class="keyword">is</span> <span class="keyword">not</span> <span class="built_in">str</span>:</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&#x27;请输入字符串&#x27;</span>)</span><br><span class="line">            self.__name = val</span><br><span class="line"></span><br><span class="line"><span class="meta">        @name.deleter</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">name</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;不允许删除&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    obj1 = People(<span class="string">&#x27;Ame&#x27;</span>)</span><br><span class="line">    <span class="comment"># obj1.get_name()</span></span><br><span class="line">    <span class="comment"># obj1.set_name(&#x27;Yuki&#x27;)</span></span><br><span class="line">    <span class="comment"># obj1.get_name()</span></span><br><span class="line">    obj1.name</span><br><span class="line">    obj1.name = <span class="string">&#x27;Yuki&#x27;</span></span><br><span class="line">    obj1.name</span><br><span class="line">    obj1.name</span><br><span class="line">    <span class="keyword">del</span> obj1.name</span><br></pre></td></tr></table></figure>

<h2 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>什么是继承</span><br><span class="line">	<span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">	继承其实就是新创建的类，新创建的子类可以又叫派生类，父类又可以叫基类或者超类</span></span><br><span class="line"><span class="string">    需要注意的是python支持多继承  即一个字累可以有一个父类或者多个父类，子类可以继承父类的数据</span></span><br><span class="line"><span class="string">    ps:  python2的继承分为经典式和新式类之分</span></span><br><span class="line"><span class="string">            新式类：继承了object的子类，以及子类的子类子子类</span></span><br><span class="line"><span class="string">            经典类：没有继承了object的子类，以及子类的子类子子类</span></span><br><span class="line"><span class="string">    	但是python3里没有这么分，所有的都会默认继承object，所以都是新式类</span></span><br><span class="line"><span class="string">    多继承的优点缺点</span></span><br><span class="line"><span class="string">    	优点  子类继承了多父类所有东西，代码能更简洁，更加被利用化</span></span><br><span class="line"><span class="string">    	缺点  1 违背了人的正常逻辑，不可能拥有多个“父亲”</span></span><br><span class="line"><span class="string">    		 2 代码可读性会变得很差</span></span><br><span class="line"><span class="string">    		 3 不建议用到多继承，有可能会遇到可恶的菱形问题，扩展性也会变差</span></span><br><span class="line"><span class="string">    		 如果真得一个子类要多继承的话，得使用Mixins</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="number">2.</span>为什么用继承</span><br><span class="line">	<span class="comment"># 因为要解决类与类之间的代码冗余问题</span></span><br><span class="line">    </span><br><span class="line"><span class="number">3.</span>怎么用继承</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">School</span>:</span></span><br><span class="line">        school = <span class="string">&#x27;Oldboy&#x27;</span></span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, gender</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line">            self.gender = gender</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Student</span>(<span class="params">School</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">choose</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">f&#x27;<span class="subst">&#123;self.name&#125;</span>正在选课&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Teacher</span>(<span class="params">School</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, gender, level, salary</span>):</span></span><br><span class="line">            School.__init__(self, name, age, gender)</span><br><span class="line">            self.level = level</span><br><span class="line">            self.salary = salary</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">check</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">f&#x27;<span class="subst">&#123;self.name&#125;</span>正在批改作业&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    stu_obj = Student(<span class="string">&#x27;Ame&#x27;</span>, <span class="number">18</span>, <span class="string">&#x27;male&#x27;</span>)</span><br><span class="line">    stu_obj.choose()</span><br><span class="line">    tea_obj = Teacher(<span class="string">&#x27;Yuki&#x27;</span>, <span class="number">18</span>, <span class="string">&#x27;female&#x27;</span>, <span class="number">10</span>, <span class="number">10000</span>)</span><br><span class="line">    tea_obj.check()</span><br></pre></td></tr></table></figure>

<h2 id="单继承背景下的属性查找"><a href="#单继承背景下的属性查找" class="headerlink" title="单继承背景下的属性查找"></a>单继承背景下的属性查找</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f1</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;Foo.f1&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f2</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;Foo.f2&#x27;</span>)</span><br><span class="line">        self.f1()</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Bar</span>(<span class="params">Foo</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f1</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;Bar.f1&quot;</span>)</span><br><span class="line">obj = Bar()</span><br><span class="line">obj.f2()  <span class="comment"># Foo.f2  Bar.f1</span></span><br><span class="line"><span class="comment"># 我们会发现后来没有找到Foo.f1，找到了Bar.f1，因为self是obj给的，所以后来就去Bar里找f1，那么我们怎么找到Foo.f1呢</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 示范一</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f1</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;Foo.f1&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f2</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;Foo.f2&#x27;</span>)</span><br><span class="line">        Foo.f1(self)</span><br><span class="line">        <span class="comment"># self.f1()</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Bar</span>(<span class="params">Foo</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f1</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;Bar.f1&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">obj = Bar()</span><br><span class="line">obj.f2()</span><br><span class="line">    </span><br><span class="line"><span class="comment"># 示范二</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__f1</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;Foo.f1&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f2</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;Foo.f2&#x27;</span>)</span><br><span class="line">        self.__f1()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Bar</span>(<span class="params">Foo</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">f1</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&quot;Bar.f1&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">obj = Bar()</span><br><span class="line">obj.f2()</span><br></pre></td></tr></table></figure>

<h2 id="菱形问题-钻石问题"><a href="#菱形问题-钻石问题" class="headerlink" title="菱形问题(钻石问题)"></a>菱形问题(钻石问题)</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>什么是菱形问题</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">test</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;A&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>(<span class="params">A</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">test</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;B&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params">A</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">test</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;C&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">D</span>(<span class="params">B, C</span>):</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">obj = D()</span><br><span class="line">obj.test()  <span class="comment"># 像这样的就是菱形问题，D------B, C------A  注意 C--------B, A------object  这样不是菱形问题</span></span><br><span class="line"><span class="comment"># 像这样遇到B, C同级应该会选择B还是C呢，查找方法得依靠C3算法得出来的MRO，注意 python2没有MRO</span></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">A</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">test</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;A&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">B</span>(<span class="params">A</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">test</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;B&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params">A</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">test</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;C&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">D</span>(<span class="params">B, C</span>):</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj = D()</span><br><span class="line">    obj.test()</span><br><span class="line">    <span class="built_in">print</span>(D.mro()) </span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">[&lt;class &#x27;__main__.D&#x27;&gt;, &lt;class &#x27;__main__.B&#x27;&gt;, &lt;class &#x27;__main__.C&#x27;&gt;, &lt;class &#x27;__main__.A&#x27;&gt;, &lt;class &#x27;object&#x27;&gt;]</span></span><br><span class="line"><span class="string">就会依靠这个去寻找</span></span><br><span class="line"><span class="string">注意 1.子类会先于父类被检查</span></span><br><span class="line"><span class="string">	2.多个父类会根据他们在列表中的顺序检查</span></span><br><span class="line"><span class="string">	3.下一类存在多个合法的选择，就会选择第一个父类</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="非菱形问题的属性查找顺序"><a href="#非菱形问题的属性查找顺序" class="headerlink" title="非菱形问题的属性查找顺序"></a>非菱形问题的属性查找顺序</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 经典式与新式类 之间查找顺序都是一样的</span></span><br></pre></td></tr></table></figure>

<h2 id="菱形问题的属性查找顺序"><a href="#菱形问题的属性查找顺序" class="headerlink" title="菱形问题的属性查找顺序"></a>菱形问题的属性查找顺序</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 经典类是深度查找，即一路走到黑，找不到再往右边去搜寻</span></span><br><span class="line"><span class="comment"># 新式类是广度查找，即每一路都走，但是不找最后，往右边全部搜寻完了，再去找最后一个</span></span><br></pre></td></tr></table></figure>

<h2 id="Mixins机制"><a href="#Mixins机制" class="headerlink" title="Mixins机制"></a>Mixins机制</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Vehicle</span>:</span>  <span class="comment"># 交通工具</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Helicopter</span>(<span class="params">Vehicle</span>):</span>  <span class="comment"># 直升飞机</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">fly</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">CivilAircraft</span>(<span class="params">Vehicle</span>):</span>  <span class="comment"># 民航飞机</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">fly</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Car</span>(<span class="params">Vehicle</span>):</span>  <span class="comment"># 小轿车</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">从这可以看出 飞机们都有飞行的功能，我们应该把飞行功能代码都写入父类，防止代码冗余，但是这样的话</span></span><br><span class="line"><span class="string">小汽车：？？？，我也会飞了</span></span><br><span class="line"><span class="string">所以我们并不能把飞行功能加入交通工具这个父类</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="comment"># 处理办法</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Vehicle</span>:</span>  <span class="comment"># 交通工具</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Aircraft</span>:</span>  <span class="comment"># 飞行器</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">fly</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Helicopter</span>(<span class="params">Aircraft, Vehicle</span>):</span>  <span class="comment"># 直升飞机</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">CivilAircraft</span>(<span class="params">Aircraft, Vehicle</span>):</span>  <span class="comment"># 民航飞机</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Car</span>(<span class="params">Vehicle</span>):</span>  <span class="comment"># 小轿车</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">我们加入了个新父类，来解决汽车不能飞，但是飞机能飞的问题，</span></span><br><span class="line"><span class="string">但是直升飞机和民航飞机就发出了疑问：？？怎么我们有了两个亲爹</span></span><br><span class="line"><span class="string">所以这样是不合人的逻辑了，所以mixin跳了出来，摇了摇头，帮助他们解决了问题</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Vehicle</span>:</span>  <span class="comment"># 交通工具</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">AircraftMixin</span>:</span>  <span class="comment"># 飞行器</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">fly</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Helicopter</span>(<span class="params">AircraftMixin, Vehicle</span>):</span>  <span class="comment"># 直升飞机</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">CivilAircraft</span>(<span class="params">AircraftMixin, Vehicle</span>):</span>  <span class="comment"># 民航飞机</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Car</span>(<span class="params">Vehicle</span>):</span>  <span class="comment"># 小轿车</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">mixin其实不是特殊的直白有效的代码，只是一个标志，一个功能的标志，往一个类加入这个Mixin就代表他其实不是真正的父亲，只是一个功能的代表，真正的亲爹是交通工具</span></span><br><span class="line"><span class="string">同时也要注意mixin用法也有限制！！！！</span></span><br><span class="line"><span class="string">	1. mixin代表的是一个功能，不要代表一个物品，python 对于mixin类的命名方式一般以 Mixin, able, ible 为后缀</span></span><br><span class="line"><span class="string">	2. 然后他的责任很单一，如果有多种类功能，则要写多个mixin，不能挤一块，一个类是可以多继承很多mixin的</span></span><br><span class="line"><span class="string">	3.他不依赖于子类的实现</span></span><br><span class="line"><span class="string">	4.子类就算没有继承mixin，他还是能进行，只不过缺少了功能，比如，飞机没有继承飞，但是他还是可以载客</span></span><br><span class="line"><span class="string">Mixins是从多个类中重用代码的好方法，但是需要付出相应的代价，我们定义的Minx类越多，子类的代码可读性就会越差，并且更恶心的是，在继承的层级变多时，代码阅读者在定位某一个方法到底在何处调用时会晕头转向</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>

<h2 id="在子类派生的新方法中重用父类的功能"><a href="#在子类派生的新方法中重用父类的功能" class="headerlink" title="在子类派生的新方法中重用父类的功能"></a>在子类派生的新方法中重用父类的功能</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在子类中直接调用父类的功能</span></span><br><span class="line">	 <span class="class"><span class="keyword">class</span> <span class="title">School</span>:</span></span><br><span class="line">        school = <span class="string">&#x27;Oldboy&#x27;</span></span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, gender</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line">            self.gender = gender</span><br><span class="line"></span><br><span class="line">            </span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Teacher</span>(<span class="params">School</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, gender, level, salary</span>):</span></span><br><span class="line">            School.__init__(self, name, age, gender)</span><br><span class="line">            self.level = level</span><br><span class="line">            self.salary = salary</span><br><span class="line">            </span><br><span class="line"><span class="comment"># super()调用父类提供给自己的方法----严格依赖继承关系</span></span><br><span class="line"><span class="comment"># 调用super()会得到一个特殊的对象，会自动追寻当前类MRO，去当前父类中找属性</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">School</span>:</span></span><br><span class="line">        school = <span class="string">&#x27;Oldboy&#x27;</span></span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, gender</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line">            self.gender = gender</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Teacher</span>(<span class="params">School</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, gender, level, salary</span>):</span></span><br><span class="line">            <span class="built_in">super</span>().__init__(name, age, gender)  <span class="comment"># 传入的是方法，自动调用对象，所以不用加self</span></span><br><span class="line">            self.level = level</span><br><span class="line">            self.salary = salary</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    tea_obj = Teacher(<span class="string">&#x27;Ame&#x27;</span>, <span class="number">18</span>, <span class="string">&#x27;male&#x27;</span>, <span class="number">10</span>, <span class="number">10000</span>)</span><br><span class="line">    <span class="built_in">print</span>(Teacher.mro())</span><br><span class="line">    <span class="built_in">print</span>(tea_obj.__dict__)</span><br></pre></td></tr></table></figure>

<h2 id="多态与鸭子类型"><a href="#多态与鸭子类型" class="headerlink" title="多态与鸭子类型"></a>多态与鸭子类型</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>什么是多态</span><br><span class="line">其实就是一个事物有多种形态</span><br><span class="line"><span class="number">2.</span>在程序中表达多态</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Animal</span>:</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">People</span>(<span class="params">Animal</span>):</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Dog</span>(<span class="params">Animal</span>):</span></span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Pig</span>(<span class="params">Animal</span>):</span></span><br><span class="line">        <span class="keyword">pass</span>  </span><br><span class="line"><span class="comment"># 动物就有多种形态，称之为多态，那么多态的好处是什么呢，就比如动物都会叫</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Animal</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;动物都会叫....&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">People</span>(<span class="params">Animal</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">super</span>().say()</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;嘤嘤嘤&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Dog</span>(<span class="params">Animal</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">super</span>().say()</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;汪汪汪&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Pig</span>(<span class="params">Animal</span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">super</span>().say()</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;哼哼哼&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj1 = People()</span><br><span class="line">    obj2 = Dog()</span><br><span class="line">    obj3 = Pig()</span><br><span class="line">    obj1.say()</span><br><span class="line">    obj2.say()</span><br><span class="line">    obj3.say()</span><br><span class="line">    <span class="comment"># 好处就是我们在调用子类的时候并不用想子类是什么，只用想着父类就是动物，肯定会叫，这是所有的语言多态的优点，但是python有更好玩的，那就是鸭子类型</span></span><br><span class="line">    <span class="number">3.</span>什么是鸭子类型</span><br><span class="line">    	其实就是比如 一个人在街上模仿鸭子叫声，走路，甚至还去河里游泳，我们就可以去把这个当成鸭子，代码也一样的道理，如果都没有指定父类，但是他们都有相似之处，就直接当成是一样来看</span><br><span class="line">        <span class="class"><span class="keyword">class</span> <span class="title">Cpu</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">read</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;cpu read&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">write</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;cpu write&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Memory</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">read</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;Memory read&#x27;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">write</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;Memory write&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Txt</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">read</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;txt read&#x27;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">write</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;txt write&#x27;</span>)</span><br><span class="line">    obj1 = Cpu()</span><br><span class="line">    obj2 = Memory()</span><br><span class="line">    obj3 = Txt()</span><br><span class="line">    obj2.write()</span><br><span class="line">    obj1.write()</span><br><span class="line">    obj3.write()</span><br><span class="line">    <span class="comment"># 正如cpu Memory都是硬件，TXT则是软件，真要分父类是分开的，但是他们都有读写功能，所以就可以看作一块，这就是鸭子类型</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="classmethod与绑定方法"><a href="#classmethod与绑定方法" class="headerlink" title="classmethod与绑定方法"></a>classmethod与绑定方法</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>绑定方法</span><br><span class="line">	特殊之处在于将调用者本身传入给第一个参数</span><br><span class="line">    <span class="comment"># 绑定给对象的方法  调用者是对象 传入的也是对象</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Mysql</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, ip, port</span>):</span></span><br><span class="line">            self.ip = ip</span><br><span class="line">            self.port = port</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    obj1 = Mysql(<span class="string">&#x27;1,0,1,0&#x27;</span>, <span class="number">3306</span>)</span><br><span class="line">    <span class="comment"># 绑定给类的方法  调用者是类，传入的也是类</span></span><br><span class="line">	<span class="keyword">import</span> setting</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	<span class="class"><span class="keyword">class</span> <span class="title">Mysql</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, ip, port</span>):</span></span><br><span class="line">            self.ip = ip</span><br><span class="line">            self.port = port</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">f&#x27;<span class="subst">&#123;self.ip&#125;</span><span class="subst">&#123;self.port&#125;</span>&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="meta">        @classmethod</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">from_conf</span>(<span class="params">cls</span>):</span></span><br><span class="line">            <span class="keyword">return</span> cls(setting.IP, setting.PORT)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        obj1 = Mysql.from_conf()</span><br><span class="line">        <span class="built_in">print</span>(obj1.__dict__)</span><br><span class="line">        </span><br><span class="line">        <span class="comment"># 在setting文件里放了IP 和 PORT，直接这里调用</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="staticmethod与非绑定方法"><a href="#staticmethod与非绑定方法" class="headerlink" title="staticmethod与非绑定方法"></a>staticmethod与非绑定方法</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 非绑定方法其实就是静态方法，当一个函数不需要对象也不需要类的时候，但是想放在类下面，就用@staticmethod装饰器</span></span><br><span class="line"><span class="comment"># 没有绑定给任何人，调用者可以是类 可以是对象 不会有自动传入参数的效果</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Mysql</span>:</span></span><br><span class="line">            <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, ip, port</span>):</span></span><br><span class="line">                self.ip = ip</span><br><span class="line">                self.port = port</span><br><span class="line">                </span><br><span class="line"><span class="meta">            @staticmethod    </span></span><br><span class="line">            <span class="function"><span class="keyword">def</span> <span class="title">creat_id</span>():</span></span><br><span class="line">                <span class="keyword">import</span> uuid</span><br><span class="line">                <span class="keyword">return</span> uuid.uui4()</span><br><span class="line">            </span><br></pre></td></tr></table></figure>

<h2 id="反射"><a href="#反射" class="headerlink" title="反射"></a>反射</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 什么是反射</span></span><br><span class="line">	反射就是一个对象(不见棺材不落泪)到最后才知道他是什么属性</span><br><span class="line"> </span><br><span class="line"><span class="comment"># 为什么要用反射</span></span><br><span class="line">	因为假如在一个类中，传入了对象，然后想找到对象的属性，用反射就很容易找到</span><br><span class="line">    </span><br><span class="line"><span class="comment"># 怎么用反射</span></span><br><span class="line">	<span class="class"><span class="keyword">class</span> <span class="title">School</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">f&#x27;&lt;<span class="subst">&#123;self.name&#125;</span>,<span class="subst">&#123;self.age&#125;</span>&gt;&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	obj = School(<span class="string">&#x27;Ame&#x27;</span>, <span class="number">10</span>)</span><br><span class="line">    <span class="comment"># 假如在以后的工作中，你的同事写好了代码跟你交接，你只知道有个对象obj，该怎么知道obj的属性是什么呢</span></span><br><span class="line">    <span class="comment"># 要用到dir()方法</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="built_in">dir</span>(obj))  <span class="comment"># [&#x27;__class__&#x27;, &#x27;__delattr__&#x27;, &#x27;__dict__&#x27;, &#x27;__dir__&#x27;, &#x27;__doc__&#x27;, &#x27;__eq__&#x27;, .......]</span></span><br><span class="line">    <span class="comment"># dir()会显示出obj所有的属性，所以在运用反射的4个内置函数便OK</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="built_in">hasattr</span>(obj, <span class="string">&#x27;name&#x27;</span>))  <span class="comment"># hasattr 是判断有没有这个属性   True</span></span><br><span class="line">    <span class="built_in">print</span>(<span class="built_in">getattr</span>(obj, <span class="string">&#x27;name&#x27;</span>))  <span class="comment"># getattr 是调出这个属性的值     Ame</span></span><br><span class="line">    <span class="built_in">setattr</span>(obj, <span class="string">&#x27;name&#x27;</span>, <span class="string">&#x27;Yuki&#x27;</span>)  </span><br><span class="line">    <span class="built_in">print</span>(obj.name)  <span class="comment"># setattr 是修改这个属性        Yuki</span></span><br><span class="line">    <span class="built_in">delattr</span>(obj, <span class="string">&#x27;name&#x27;</span>)  <span class="comment"># delattr 删除这个属性</span></span><br><span class="line">   </span><br><span class="line"><span class="comment"># 用途案例</span></span><br><span class="line">	<span class="class"><span class="keyword">class</span> <span class="title">People</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">put</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&quot;lalala&quot;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&quot;lblblb&quot;</span>)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">interactive</span>(<span class="params">self</span>):</span></span><br><span class="line">            methon = <span class="built_in">input</span>(<span class="string">&#x27;------&gt;&#x27;</span>)</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">hasattr</span>(self, methon):</span><br><span class="line">                <span class="built_in">print</span>(self, methon)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&#x27;指令不存在&#x27;</span>)</span><br><span class="line">	</span><br><span class="line">    obj = People()</span><br><span class="line">    obj.interactive()</span><br><span class="line"><span class="comment"># 从这可以看出，发射就是用来判断未知的对象属性的</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="内置方法"><a href="#内置方法" class="headerlink" title="内置方法"></a>内置方法</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 什么是内置方法</span></span><br><span class="line">	以__开头__结尾的就是内置方法</span><br><span class="line">	特点 会自动触发调用</span><br><span class="line">    </span><br><span class="line"><span class="comment"># 为什么用内置方法</span></span><br><span class="line">	为了定制化我们的类或者对象</span><br><span class="line">    </span><br><span class="line"><span class="comment"># __str__ ：打印对象时，自动触发，然后会将返回值显示出来</span></span><br><span class="line">	<span class="class"><span class="keyword">class</span> <span class="title">School</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__str__</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="keyword">return</span> <span class="string">f&#x27;<span class="subst">&#123;self.name&#125;</span>,<span class="subst">&#123;self.age&#125;</span>&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj = School(<span class="string">&#x27;Ame&#x27;</span>, <span class="number">18</span>)</span><br><span class="line">    <span class="built_in">print</span>(obj)  <span class="comment"># Ame,18            由此可以看出来 直接打印对象，然后就会输出__srt__</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># __del__：删除的时候会自动调用</span></span><br><span class="line">	<span class="class"><span class="keyword">class</span> <span class="title">School</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__del__</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;lalala&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj = School(<span class="string">&#x27;Ame&#x27;</span>, <span class="number">18</span>)</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;-------------&quot;</span>) </span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    -------------</span></span><br><span class="line"><span class="string">    lalala</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="comment"># 从输出结果可以看 lalala自动打印了出来 这是为什么，因为程序结束后，pycharm要回收空间，所以会自动删除，然后__del__就打印了出来，如果在print之前删除呢</span></span><br><span class="line">    </span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">School</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age</span>):</span></span><br><span class="line">            self.name = name</span><br><span class="line">            self.age = age</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__del__</span>(<span class="params">self</span>):</span></span><br><span class="line">            <span class="built_in">print</span>(<span class="string">&#x27;lalala&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    obj = School(<span class="string">&#x27;Ame&#x27;</span>, <span class="number">18</span>)</span><br><span class="line">    <span class="keyword">del</span> obj</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;-------------&quot;</span>)</span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    lalala</span></span><br><span class="line"><span class="string">    -------------</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="comment"># 所以__del__是删除的时候会自动调用，那么这个用途在哪的，我们在一个程序结束后，pycharm会自动回收，但是只是回收自己的空间，操作系统的并没有回收，所以__del__是用来告诉pycharm回收系统空间的</span></span><br><span class="line">    </span><br></pre></td></tr></table></figure>

<h2 id="元类"><a href="#元类" class="headerlink" title="元类"></a>元类</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 引入</span></span><br><span class="line">	一切皆是对象</span><br><span class="line">   </span><br><span class="line"><span class="comment"># 什么是元类</span></span><br><span class="line">	用来实例化产生的类的类</span><br><span class="line">    关系： 元类-------实例化-------类---------实例化--------对象</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看内置的元类：我们用class关键字定义的所有的类以及内置的类都由内置的元类type实例化产生的</span></span><br></pre></td></tr></table></figure>

<h2 id="class的机制"><a href="#class的机制" class="headerlink" title="class的机制"></a>class的机制</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># class其实是由以下的步骤产生</span></span><br><span class="line">    class_name = <span class="string">&#x27;People&#x27;</span></span><br><span class="line">    class_bases = (<span class="built_in">object</span>,)</span><br><span class="line">    class_dir = &#123;&#125;</span><br><span class="line">    class_body = <span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">    def __init__(self, name, age):</span></span><br><span class="line"><span class="string">        self.name = name</span></span><br><span class="line"><span class="string">        self.age = age</span></span><br><span class="line"><span class="string">    def __del__(self):</span></span><br><span class="line"><span class="string">        print(&#x27;lalala&#x27;)</span></span><br><span class="line"><span class="string">    &#x27;&#x27;&#x27;</span></span><br><span class="line">    <span class="built_in">exec</span>(class_body, &#123;&#125;, class_dir)</span><br><span class="line">    <span class="built_in">print</span>(<span class="built_in">type</span>(class_name, class_bases, class_dir))  <span class="comment"># &lt;class &#x27;__main__.People&#x27;&gt;</span></span><br><span class="line"><span class="comment"># 这种方法是自定义元类的精髓</span></span><br><span class="line">    </span><br><span class="line"><span class="comment"># 其实平时 class People  的People 并不是类， 只是个变量名而已， 其中的功能代码集体才是一个类</span></span><br></pre></td></tr></table></figure>

<h2 id="自定义元类"><a href="#自定义元类" class="headerlink" title="自定义元类"></a>自定义元类</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Mymeta</span>(<span class="params"><span class="built_in">type</span></span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self,x ,y ,z</span>):</span>  <span class="comment"># 这边必须要传四个参数， 因为class people的存在会把class过程的参数传给Mymeta</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;123&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">People</span>(<span class="params">metaclass=Mymeta</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age</span>):</span></span><br><span class="line">        self.name = name</span><br><span class="line">        self.bases = age</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="string">f&#x27;&lt;<span class="subst">&#123;self.name&#125;</span>,<span class="subst">&#123;self.age&#125;</span>&gt;&#x27;</span>)</span><br></pre></td></tr></table></figure>


            </div>

            <!-- Post Comments -->
            
    <!-- 使用 DISQUS_CLICK -->
<div id="disqus-comment">
    <div id="disqus_thread"></div>

<!-- add animation -->
<style>
	.disqus_click_btn {
            line-height: 30px;
            margin: 0;
            min-width: 50px;
            padding: 0 14px;
            display: inline-block;
            font-family: "Roboto", "Helvetica", "Arial", sans-serif;
            font-size: 14px;
            font-weight: 400;
            text-transform: uppercase;
            letter-spacing: 0;
            overflow: hidden;
            will-change: box-shadow;
            transition: box-shadow .2s cubic-bezier(.4, 0, 1, 1), background-color .2s cubic-bezier(.4, 0, .2, 1), color .2s cubic-bezier(.4, 0, .2, 1);
            outline: 0;
            cursor: pointer;
            text-decoration: none;
            text-align: center;
            vertical-align: middle;
            border: 0;
            background: rgba(158, 158, 158, .2);
            box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
            color: #fff;
            background-color: #7EC0EE;
            text-shadow: 0
        }
</style>
	
<div class="btn_click_load" id="disqus_bt"> 
    <button class="disqus_click_btn">点击查看评论</button>
</div>

<!--
<script type="text/javascript">
$('.btn_click_load').click(function() {
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'http-miccall-tech'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    document.getElementById('disqus_bt').style.display = "none";
});
</script>
-->
<script type="text/javascript">
    var disqus_config = function () {
        this.page.url = 'https://gitee.com/AmeX/amelin-ting.git/2017/03/30/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/';  // Replace PAGE_URL with your page's canonical URL variable
        this.page.identifier = 'https://gitee.com/AmeX/amelin-ting.git/2017/03/30/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
</script>

<script type="text/javascript">
    $('.btn_click_load').click(function() {  //click to load comments
        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document;
            var s = d.createElement('script');
            s.src = '//http-miccall-tech.disqus.com/embed.js';
            s.setAttribute('data-timestamp', + new Date());
            (d.head || d.body).appendChild(s);
        })();
        $('.btn_click_load').css('display','none');
    });
</script>
</div>
<style>
    #disqus-comment{
        background-color: #eee;
        padding: 2pc;
    }
</style>


        </div>
        <!-- Copyright 版权 start -->
                <div id="copyright">
            <ul>
                <li>&copy;Powered By <a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/" style="border-bottom: none;">hexo</a></li>
                <li>Design: <a target="_blank" rel="noopener" href="http://miccall.tech " style="border-bottom: none;">miccall</a></li>
            </ul>
            
                <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
			
        </div>
    </div>
</body>



 	
</html>
